package com.dji.sample.manage.controller.client;

import com.dji.sample.common.model.PageResult;
import com.dji.sample.manage.model.dto.DeviceDTO;
import com.dji.sample.manage.service.IDeviceService;
import com.dji.sdk.common.HttpResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.SQLException;
import java.util.List;

@RestController
@RequestMapping("/api/manage")
public class ManageInterface {

    @Autowired
    private IDeviceService deviceService;

    @GetMapping("/getDeviceBySn/{sn}")
    public HttpResultResponse<DeviceDTO> getDeviceBySn(@PathVariable("sn") String sn) throws SQLException {
        DeviceDTO deviceDTO = deviceService.getDeviceBySn(sn).orElse(null);
        return HttpResultResponse.success(deviceDTO);
    }

    @GetMapping("/getAllDroneDevice")
    public HttpResultResponse<PageResult<DeviceDTO>> getAllDroneDevice() throws SQLException {
        PageResult<DeviceDTO> deviceDTOList = deviceService.getAllDroneDevice();
        return HttpResultResponse.success(deviceDTOList);
    }

    @GetMapping("/getGateWay")
    public HttpResultResponse<List<DeviceDTO>> getGateWay() throws SQLException {
        List<DeviceDTO> deviceDTOList = deviceService.getGateWay();
        return HttpResultResponse.success(deviceDTOList);
    }
}
